//
//  HotDetailUpTableViewCell.m
//  礼物go
//
//  Created by dllo on 16/5/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HotDetailUpTableViewCell.h"

#define marginSpace 10
#define nameLabelH 50

@interface HotDetailUpTableViewCell ()


@property(nonatomic,strong)UILabel *nameLabel;
@property(nonatomic,strong)UILabel *priceLabel;
@property(nonatomic,strong)UIImageView *moneyIcon;
@property(nonatomic,strong)UILabel *descriptionLabel;

@end

@implementation HotDetailUpTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

-(void)createSubviews{
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(marginSpace, marginSpace * 0.2, SCREENWIDTH - marginSpace * 2, nameLabelH)];
   // self.nameLabel.backgroundColor = [UIColor yellowColor];
    self.nameLabel.text = @"标题";
    self.nameLabel.numberOfLines = 0;
    self.nameLabel.font = [UIFont systemFontOfSize:20];
    [self.contentView addSubview:self.nameLabel];
   // self.nameLabel.textColor = [UIColor grayColor];
    
    self.moneyIcon = [[UIImageView alloc] initWithFrame:CGRectMake(marginSpace, self.nameLabel.frame.origin.y + nameLabelH, 20, 20)];
    [self.contentView addSubview:self.moneyIcon];
    self.moneyIcon.image = [UIImage imageNamed:@"money"];
    
    self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.moneyIcon.frame.origin.x + self.moneyIcon.frame.size.width, self.moneyIcon.frame.origin.y, 100, self.moneyIcon.frame.size.height)];
   // self.priceLabel.backgroundColor = [UIColor yellowColor];
    self.priceLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:self.priceLabel];
    
    self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(marginSpace, self.moneyIcon.frame.origin.y + self.moneyIcon.frame.size.height + 5, SCREENWIDTH - marginSpace * 2, 20)];
   // self.descriptionLabel.backgroundColor = [UIColor yellowColor];
    self.descriptionLabel.numberOfLines = 0;
//    [self.descriptionLabel sizeToFit];
    self.descriptionLabel.textColor = [UIColor lightGrayColor];
      [self.contentView addSubview:self.descriptionLabel];
    //self.cellHeight = self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height + 10;
}

//-(void)layoutSubviews{
//    [super layoutSubviews];
//    self.descriptionLabel.frame = CGRectMake(marginSpace, self.moneyIcon.frame.origin.y + self.moneyIcon.frame.size.height + 5, SCREENWIDTH - marginSpace * 2, 0);
//    self.descriptionLabel.numberOfLines = 0;
//    [self.descriptionLabel sizeToFit];
//  // NSInteger cellHeight = self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height + 10;
//    
//}

-(void)setHotDetail:(HotDetailModel *)hotDetail{
    _hotDetail = hotDetail;
    self.nameLabel.text = _hotDetail.name;
    self.priceLabel.text = _hotDetail.price;
    
    self.descriptionLabel.text = _hotDetail.detailDescription;
    CGRect rect = self.descriptionLabel.frame;
    rect.size.height = [self getHeightForCellByModel:hotDetail] - CGRectGetMaxY(self.priceLabel.frame) - 5;
    self.descriptionLabel.frame = rect;
    
  }

- (CGFloat)getHeightForCellByModel:(HotDetailModel *)hotDetail{
    
    //  return CGRectGetMaxY(self.describeLabel.frame) + 5;
    CGRect rect = [hotDetail.detailDescription boundingRectWithSize:CGSizeMake(self.descriptionLabel.frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
    
    return rect.size.height + self.descriptionLabel.frame.origin.y;
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
